package com.jf.dao.impl;

import com.jf.bean.ProjectImg;
import com.jf.dao.ProjectImgDao;
import com.jf.util.BaseDao;

import java.util.ArrayList;
import java.util.List;

public class ProjectImgDaoImpl implements ProjectImgDao {
    @Override
    public void batchInsert(List<ProjectImg> list) {
        List<Object> objs = new ArrayList<>();
        StringBuilder sql = new StringBuilder("insert into project_img values");
        for(ProjectImg pi : list){
            sql.append("(null,?,?),");
            objs.add(pi.getProjectId());
            objs.add(pi.getSrc());
        }
        sql=new StringBuilder(sql.substring(0,sql.lastIndexOf(",")));
        BaseDao.baseBatch(sql.toString(), list.size(), objs);
    }

    @Override
    public List<ProjectImg> getListByProjectId(String projectId) {
        String sql = "select * from project_img where project_id = ?";
        return BaseDao.baseQuery(ProjectImg.class,sql,projectId);
    }

    @Override
    public void deleteByProjectId(String projectId) {
        String sql = "delete from project_img where project_id = ?";
        BaseDao.baseUpdate(sql, projectId);
    }
}
